package com.ajie.jdbc;

import com.ajie.jdbc.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author wyj
 * @since 2022/1/19
 */
public class Test01 {
    public static void main(String[] args) throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        /**
         * test02中通过接口也最终是通过sqlSession执行对应的方法，也会走到这一步，只是交给代理对象去做了；
         */
        User user = (User) sqlSession.selectOne("com.ajie.jdbc.dao.UserDao.selectUserById", 1);
        System.out.println(user);

    }
}
